
package com.example.javapracticaltraining.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.javapracticaltraining.entity.R;
import com.example.javapracticaltraining.entity.pojo.Users;
import com.example.javapracticaltraining.mapper.UsersMapper;
import com.example.javapracticaltraining.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UsersMapper usersMapper;

    @Override
    public R<Users> login(String username, String password) {
        LambdaQueryWrapper<Users> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Users::getUsername, username);
        Users user = usersMapper.selectOne(queryWrapper);

        if (user == null) {
            return R.error("用户不存在");
        }

        // 实际项目中密码需要加密后比对
        if (!user.getPassword().equals(password)) {
            return R.error("密码错误");
        }

        return R.success(user);
    }
}


